/**
 * Created Date: Saturday, April 8th 2023, 1:51:33 pm
 * Author: CodingGorit
 * -----
 * Last Modified: Sat Apr 08 2023
 * Modified By: CodingGorit
 * -----
 * Copyright © 2019 —— 2023 fmin-courses All Rights Reserved
 * ------------------------------------
 * Javascript will save your soul!
 */

import { IPage } from '@/types';
import request from '@/utils/request';

const http = request.getInstance();

const adminApi = {
	Login: '/admin/login',
	Logout: '/user/logout',
	AdminDetail: '/admin/info/',
	AdminOperate: '/admin',
	AdminByPage: '/admin/page',
	AdminOperateWithPermission: '/api/v1/private/admin'
}

/**
 * 管理员登录
 * login func
 * @param {Object} param
 */
export function login(param: any) {
	return http.request({
		url: adminApi.Login,
		method: 'post',
		data: param
	})
}

/**
 * 查询管理员信息
 * @param {Object} id
 */
export function getAdminInfo(id: string) {
	return http.get({
		url: adminApi.AdminDetail + id
	})
}

/**
 * 添加管理员
 * @param {Object} data
 */
export function addAdmin(data: any) {
	return http.request({
		url: adminApi.AdminOperate,
		method: 'post',
		data: data
	})
}

/**
 * 更新管理员
 * @param {Object} data
 */
export function updateAdmin(data: any) {
	return http.request({
		url: adminApi.AdminOperate,
		method: 'put',
		data: data
	})
}

/**
 * 删除管理员
 * @param {Object} id
 */
export function deleteAdmin(id: string) {
	return http.request({
		url: adminApi.AdminOperate + `/${id}`,
		method: 'delete'
	})
}

/**
 * 分页查询管理员列表
 * @param {Object} page
 */
export function getAdminByPage(page: IPage) {
	return http.request({
		url: adminApi.AdminByPage,
		method: 'post',
		data: page
	})
}
